package com.todod.common.util;

import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

import lombok.Data;

/**
 * @ClassName: Result
 * @Author: jdh
 * @CreateTime: 2022-03-15
 * @Description:
 */
@Data
@Component
public class Result<T> {

	private T data;

	private Integer code;

	private String msg;

	private String msg2;

	public Result() {
	}

	public Result(T data, Integer code, String msg) {
		this.data = data;
		this.code = code;
		this.msg = msg;
	}

	public Result(T data, Integer code, String msg, String msg2) {
		this.data = data;
		this.code = code;
		this.msg = msg;
		this.msg2 = msg2;
	}

	public static <T> Result<T> success() {
		return new Result<>(null, HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase());
	}

	public static <T> Result<T> success(T data) {
		return new Result<T>(data, HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase());
	}

	public static <T> Result<T> success(String msg) {
		return new Result<T>(null, HttpStatus.OK.value(), msg);
	}

	public static <T> Result<T> success(T data, String msg) {
		return new Result<T>(data, HttpStatus.OK.value(), msg);
	}

	public static <T> Result<T> success(Integer code, String msg) {
		return new Result<T>(null, code, msg);
	}

	public static <T> Result<T> success(T data, Integer code, String msg) {
		return new Result<T>(data, code, msg);
	}

	public static <T> Result<T> error() {
		return new Result<>(null, HttpStatus.INTERNAL_SERVER_ERROR.value(),
				HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
	}

	public static <T> Result<T> error(T data) {
		return new Result<T>(data, HttpStatus.INTERNAL_SERVER_ERROR.value(),
				HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
	}

	public static <T> Result<T> error(String msg) {
		return new Result<T>(null, HttpStatus.INTERNAL_SERVER_ERROR.value(), msg);
	}

	public static <T> Result<T> error(T data, String msg) {
		return new Result<T>(data, HttpStatus.INTERNAL_SERVER_ERROR.value(), msg);
	}

	public static <T> Result<T> error(Integer code, String msg) {
		return new Result<T>(null, code, msg);
	}

	public static <T> Result<T> error(T data, Integer code, String msg) {
		return new Result<T>(data, code, msg);
	}

	public static <T> Result<T> success(T data, String msg, String filePath) {
		return new Result<T>(data, HttpStatus.OK.value(), msg, filePath);
	}

}
